<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:c="http://java.sun.com/jsp/jstl/core"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:g="http://giava.by/common/base"
	template="/WEB-INF/layout/t.xhtml">

	<ui:define name="title">
		<h:outputText value="Gestione Prodotti e Sinistri" />
	</ui:define>
	<ui:define name="roles">
		<f:attribute name="roles" value="insurance-claim" />
	</ui:define>

	<ui:define name="content">

		<script type="text/javascript"
			src="#{request.contextPath}/scripts/it_editor.js"></script>

		<script language="javascript" type="text/javascript"
			src="#{request.contextPath}/scripts/tiny_mce/tiny_mce.js"></script>

		<h:form>

			<p:messages id="messages" />
			<center>
				<p:panel header="Gestione Prodotti">

					<script language="javascript" type="text/javascript">
		tinyMCE
		.init({
			// General options
			mode : "specific_textareas",
			language : "it",
			entity_encoding : "named",
			theme : "advanced",
			editor_selector: "tinyMceTa",
			convert_urls : false,
			plugins : "fullscreen,advlink,print,contextmenu,paste,directionality,noneditable,visualchars,nonbreaking,xhtmlxtras,template,table",
			// Theme options ... ho tolto il pulsante imgBrows.. in notizie si mettono tramite il form di upload sotto, no?
			theme_advanced_buttons1 : "fullscreen,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,fontsizeselect,fontselect,|,hr,|,cut,copy,paste,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,cleanup,|,code",
			theme_advanced_buttons2 : "tablecontrols,|,link,unlink",
			theme_advanced_buttons3 : "",
			theme_advanced_toolbar_location : "top",
			theme_advanced_toolbar_align : "left",
			theme_advanced_fonts : "Arial=Arial;Courier New=Courier New;Times New Roman=Times New Roman;",
			theme_advanced_resizing : true,
			setup : function(ed) {
				<f:verbatim rendered="#{not copertina}">
				// Add a custom button
				ed
						.addButton(
								'imgBrows',
								{
									title : 'Browser immagini',
									image : '#{facesContext.externalContext.request.contextPath}/images/img.gif',
									onclick : function() {
										// Add you own code to execute something on click
										ed.focus();
//										ed.selection.setContent('<div id="imgHere" style="text-align:center;"></div>');
										var popupWindow = window.open('#{request.contextPath}/private/page/imagesTiny.jsf',"Browser immagini","height=600,width=800,modal=yes,alwaysRaised=yes")
										popupWindow.tinyEditor = ed;
									}
								});
				</f:verbatim>
			}
		});
</script>

					<h:panelGrid columns="2" style="width: 95%">
						<h:outputLabel for="name" value="Nome" />
						<h:inputText id="name"
							value="#{insuranceClaimProductController.element.name}"
							style="width: 100%;" required="true" />

						<h:outputLabel value="Tipologia/Categoria(*):"
							for="insuranceClaimCategoryId" />
						<h:selectOneMenu id="insuranceClaimCategoryId"
							style="width: 100%;"
							value="#{insuranceClaimProductController.element.insuranceClaimCategory.id}"
							required="true">
							<f:selectItems value="#{insuranceClaimCategoryItems}" />
						</h:selectOneMenu>

						<h:outputLabel for="orderNum" value="Indice:" style="width: 100%;" />
						<h:panelGroup layout="block">
							<p:inputText id="orderNum"
								value="#{insuranceClaimProductController.element.orderNum}" />
							<p:slider for="orderNum" />
						</h:panelGroup>

						<h:outputLabel for="code" value="Codice" />
						<h:inputText id="code"
							value="#{insuranceClaimProductController.element.code}"
							style="width: 100%;" required="true" />

						<h:outputLabel for="preview" value="Anteprima:" />
						<h:inputTextarea id="preview" cols="20" rows="20"
							value="#{insuranceClaimProductController.element.preview}"
							style=" height : 166px; width: 100%;" />


						<h:outputLabel for="description" value="Descrizione:" />
						<h:inputTextarea
							value="#{insuranceClaimProductController.element.description}"
							id="description" styleClass="tinyMceTa"
							style=" height : 166px; width: 100%;" />

					</h:panelGrid>
					<br />
				</p:panel>
				<br />
				<p:dataTable id="imgList" var="img"
					value="#{insuranceClaimProductController.element.images}"
					rowIndexVar="index2">
					<f:facet name="header">Immagini</f:facet>
					<p:column>
						<f:facet name="header">ind</f:facet>
						<h:outputText value="#{index2+1}" />
					</p:column>
					<p:column>
						<f:facet name="header">foto</f:facet>
						<h:graphicImage value="/img/#{img.filename}"
							width="#{g:imageWidthProportionalUrl('img/'.concat(img.filename),100,100)}"
							height="#{g:imageHeightProportionalUrl('img/'.concat(img.filename), 100, 100)}"
							alt="#{img.filename}" title="#{img.filename}"
							style="padding: 5px;" />
					</p:column>
					<p:column>
						<f:facet name="header">nome</f:facet>
						<h:outputText value="#{img.filename}" />
					</p:column>

					<p:column>
						<f:facet name="header">elimina</f:facet>
						<g:center>
							<h:commandLink
								action="#{insuranceClaimProductController.removeImage(img.id)}"
								value="elimina" immediate="true"
								onclick="if (!confirm('Vuoi davvero eliminare?')) return false"
								rendered="#{not empty img.id}" />
						</g:center>
					</p:column>
				</p:dataTable>

				<br />
				<p:dataTable id="docList" var="doc"
					value="#{insuranceClaimProductController.element.documents}"
					rowIndexVar="index">
					<f:facet name="header">Documenti</f:facet>
					<p:column>
						<f:facet name="header">ind</f:facet>
						<h:outputText value="#{index}" />
					</p:column>
					<p:column>
						<f:facet name="header">nome</f:facet>
						<h:outputText value="#{doc.filename}" />
					</p:column>

					<p:column>
						<f:facet name="header">elimina</f:facet>
						<g:center>
							<h:commandLink
								action="#{insuranceClaimProductController.removeDocument(img.id)}"
								value="elimina" immediate="true"
								onclick="if (!confirm('Vuoi davvero eliminare?')) return false"
								rendered="#{not empty doc.filename or not empty doc.id}" />
						</g:center>
					</p:column>
				</p:dataTable>
				<h:panelGrid columns="5">

					<h:commandButton action="#{insuranceClaimProductController.save}"
						value="Salva" immediate="false"
						rendered="#{not insuranceClaimProductController.editMode}" />

					<h:commandButton
						action="#{insuranceClaimProductController.saveAndmodDocuments}"
						value="Salva e Modifica Documenti" immediate="false"
						rendered="#{not insuranceClaimProductController.editMode}" />

					<h:commandButton action="#{insuranceClaimProductController.update}"
						value="Salva le modifiche" immediate="false"
						rendered="#{insuranceClaimProductController.editMode}" />

					<h:commandButton
						action="#{insuranceClaimProductController.updateAndmodDocuments}"
						value="Salva le modifiche e Modifica Documenti" immediate="false"
						rendered="#{insuranceClaimProductController.editMode}" />

					<h:commandButton action="#{insuranceClaimProductController.delete}"
						value="Elimina"
						rendered="#{insuranceClaimProductController.editMode}"
						immediate="true"
						onclick="if (!confirm('Vuoi davvero eliminare?')) return false" />
				</h:panelGrid>
			</center>
		</h:form>

	</ui:define>
</ui:composition>